package com.example.lean;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
        //implements View.OnClickListener
{

    Button btn;
    EditText login_id,login_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.checkview);
        //setContentView(R.layout.loginview);
        //setContentView(R.layout.textview);
        //设置文本颜色
        //TextView txt = (TextView) findViewById(R.id.title);
        //txt.setTextColor(Color.BLUE);

        //login_id = (EditText) findViewById(R.id.login_id);
        //login_password = (EditText) findViewById(R.id.login_password);
        //btn = (Button) findViewById(R.id.login_button);
        //btn.setOnClickListener(this);
    }
    public void myClick(View view){
        String  str = login_id.getText()+" "+login_password.getText();
        Toast.makeText(this,str,Toast.LENGTH_LONG).show();
    }

//    @Override
//    public void onClick(View view) {
//        String  str = login_id.getText()+" "+login_password.getText();
//        Toast.makeText(this,str,Toast.LENGTH_LONG).show();
//    }

    public void checkButtonClick(View view){

        TextView txv =  findViewById(R.id.txv);
        RadioGroup rg = findViewById(R.id.rg);

        String str = "";
        // 按选取选项 id 显示不同信息
        switch (rg.getCheckedRadioButtonId()) {
            case R.id.rb1:   // C++
                str = "C++";
                break;
            case R.id.rb2:   // C
                str = "C";
                break;
            case R.id.rb3:  // Java
                str = "Java";
                break;
            case R.id.rb4:  // C#
                txv.setText("C#");
                str = "C#";
                break;
        }
        // 用数组存放所有 CheckBox 组件的 ID
        CheckBox chk;
        int[] id = {R.id.cb_st, R.id.cb_jc, R.id.cb_xt, R.id.cb_xhx};
        for (int i : id) {    // 以循环逐一查看各 CheckBox 是否被选取
            chk = (CheckBox) findViewById(i);
            if (chk.isChecked()) {
                // 若有被选取，将换行字符及选项文字，附加到 msg 字符串后面
                str += "," + chk.getText();
            }
        }
        txv.setText("选择的是：" + str);
    }
}